package com.fancy.mobileschool.ui;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.fancy.mobileschool.R;
import com.fancy.mobileschool.entity.HduNews;
import com.fancy.mobileschool.util.Spider;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by l on 2017/10/11.
 */

public class HduNewsPageActivity extends Activity {
    private String url;
    private SwipeRefreshLayout swipeRefreshLayout;
    private HduNews hduNews;
    private TextView textView_content;
    private TextView textView_title;
    private TextView textView_info;
    private ImageView imageView;


    Handler handler=new Handler()
    {
        public void handleMessage(android.os.Message msg) {
            if(msg.what==1)
            {
                textView_title.setText(hduNews.getTitle());
                textView_info.setText(hduNews.getInfo());
                textView_content.setText(hduNews.getContent());
                Bitmap bitmap;
                if((bitmap=hduNews.getBitmap())!=null){
                    imageView.setImageBitmap(bitmap);
                }
                swipeRefreshLayout.setRefreshing(false);

            }
        };
    };


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hdunewspage);


        url=getIntent().getStringExtra("url");
        swipeRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.hdunewspage_srl);
        textView_content= (TextView) findViewById(R.id.hdunewspage_content);
        textView_title= (TextView) findViewById(R.id.hdunewspage_title);
        imageView= (ImageView) findViewById(R.id.hdunewspage_imgview);
        textView_info= (TextView) findViewById(R.id.hdunewspage_info);


        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(false);
            }
        });

        swipeRefreshLayout.setRefreshing(true);

        new getNewsThread().start();


    }



    class getNewsThread extends Thread {
        @Override
        public void run() {
            //
            hduNews= Spider.getNews(url);
            handler.sendEmptyMessage(1);
        }
    }
}
